package com.yaoran.userauth.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yaoran.userauth.dao.MenuDao;
import com.yaoran.userauth.entity.Menu;
import com.yaoran.userauth.service.MenuService;
import com.yaoran.userauth.utils.PageUtils;
import com.yaoran.userauth.utils.Query;
import com.yaoran.userauth.utils.ThreadLocalUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    private final static Logger logger = LoggerFactory.getLogger(MenuServiceImpl.class);

    @Autowired
    private MenuDao menuDao;

    @Override
    public void addMenu(Menu menu, Date createTime){

    }

    @Override
    public PageUtils<Menu> listMenu(Query query,String keyWord,int organizationId){
        Page<Menu> page = PageHelper.startPage(query.getPage(),query.getLimit());
        List<Menu> list = menuDao.listMenu(keyWord,organizationId);
        int total = (int) page.getTotal();
        return new PageUtils(list,total,query.getLimit(),query.getPage());
    }

    @Override
    public void updateMenu(Menu menu){
        menu.setUpdateTime(new Date());
        String name = ThreadLocalUtils.get("operate");
        menu.setUpdateBy(name);
        menuDao.updateMenu(menu);
    }

    @Override
    public void deleteMenu(Long id){
        menuDao.deleteMenu(id);
    }

    @Override
    public void deleteManyMenu(Long[] ids){
        menuDao.deleteManyMenus(ids);
    }

    @Override
    public Menu getMenu(Long id){
        return menuDao.getMenu(id);
    }

    @Override
    public List<Menu> applicationMenu(Long applicationId){
        return menuDao.applicationMenu(applicationId);
    }

}
